package Adventure;

import java.util.ArrayList;

enum Path
{
	NORTH(0), WEST(1), SOUTH(2), EAST(3), NORTWEST(4), NORTHEAST(5), SOUTHWEST(6), SOUTHEAST(7);
	
	private int pathNumber;
	
	Path(int _pathNumber)
	{ 
		pathNumber = _pathNumber; 
	}
	
	public int getPathNumber()
	{
		return pathNumber;
	}
}

public class Tile 
{
	private int tileNumber;
	private ArrayList<Path> tilePaths;
	private ArrayList<GameObject> tileObjects;
	private int tileAmmo = 0;
	private boolean hasEnemy;
	private ArrayList<String> enemyName;
	
	public Tile(int _number)
	{
		tileNumber = _number;
		tilePaths = new ArrayList<Path>(8);
		tileObjects = new ArrayList<GameObject>();
		hasEnemy = false;
		enemyName = new ArrayList<String>();
	}
	
	// Adds a specific path to the Tile.
	public void addPathToTile(int _pathNumber)
	{
		if(tilePaths.contains(_pathNumber))
		{
			System.out.println("Error, that path does already exist! (" + _pathNumber + "). ");
		}
		else
		{
			switch(_pathNumber)
			{
			case 0: tilePaths.add(Path.NORTH); break;
			case 1: tilePaths.add(Path.WEST); break;
			case 2: tilePaths.add(Path.SOUTH); break;
			case 3: tilePaths.add(Path.EAST); break;
			case 4: tilePaths.add(Path.NORTWEST); break;
			case 5: tilePaths.add(Path.NORTHEAST); break;
			case 6: tilePaths.add(Path.SOUTHWEST); break;
			case 7: tilePaths.add(Path.SOUTHEAST); break;
			default: System.out.println("Error! Wrong number"); break;
			}
		}
	}
	
	public ArrayList<Path> getTilePaths()
	{
		return tilePaths;
	}
	
	public void printValidPaths()
	{
		System.out.println("This tile has the following valid paths");
		
		for(int i = 0; i < tilePaths.size(); i++)
		{
			System.out.println(tilePaths.get(i));
		}
		
		System.out.println("\nFinished printed all valid paths from this tile!\n");
	}
	
	public void setTileNumber(int _number)
	{
		tileNumber = _number;
	}
	
	public int getTileNumber()
	{
		return tileNumber;
	}
	
	public ArrayList<GameObject> retrieveTileObjects()
	{
		return tileObjects;
	}
	
	public int getTileAmmo()
	{
		return tileAmmo;
	}

	public void setTileAmmo(int _ammo)
	{
		tileAmmo = _ammo;
	}
	
	public void spawnTrap(int _damage, ArrayList<String> _loreList)
	{
		tileObjects.add(new Trap("Trap", false, false, _damage, _loreList.get((int)Math.random()*_loreList.size())));
	}
	
	public void spawnDeadlyTrap(ArrayList<String> _loreList)
	{
		tileObjects.add(new Trap("Deadly Trap", false, true, 0, _loreList.get((int)Math.random()*_loreList.size())));
	}
	
	public void spawnWeapon(ArrayList<String> _weaponList)
	{
		tileObjects.add(new Weapon(_weaponList.get((int)Math.random() *_weaponList.size()), "standard", 10));
	}
	
	public void spawnProjectile(int _damage, int _nrOfProjectile)
	{
		tileObjects.add(new Projectile("Bullet", _damage, 2.1f));
		
		for(int i = 0; i < _nrOfProjectile; i++)
		{
			tileAmmo++;
		}
	}
	
	public void spawnEquippableObject(ArrayList<String> _equippableItems)
	{
		tileObjects.add(new GameObject(_equippableItems.get((int)Math.random()*_equippableItems.size()), true));
	}
	
	public void spawnEnemy(ArrayList<String> _enemies)
	{
		putEnemyOnTile(true);
		
		for(int i = 0; i < _enemies.size(); i++)
		{
			enemyName.add(_enemies.get(i));
		}
		
	}
	
	private void putEnemyOnTile(boolean _bool)
	{
		hasEnemy = _bool;
	}
	
	public boolean hasEnemy()
	{
		return hasEnemy;
	}
	
	public String enemyName()
	{
		if(hasEnemy)
		{
			return enemyName.get((int)Math.random()*enemyName.size());
		}
		else
			return "No enemy on this tile";
	}
	
	public void removeEnemy()
	{
		hasEnemy = false;
	}
	
	public void spawnSolidObject(ArrayList<String> _solidObjects)
	{
		tileObjects.add(new GameObject(_solidObjects.get((int)Math.random()*_solidObjects.size()), false));
	}
	
	// Method to use when dropping objects from the player inventory.
	public void addObjectToTile(GameObject _object)
	{
		System.out.println("Dropped the following item: " + _object);
		tileObjects.add(_object);
	}

}
